package com.ssy.lingxi.member.merchant.model.constant;

import com.ssy.lingxi.common.language.LanguageHolder;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.DropdownItem;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 会员注册来源枚举
 * @author 万宁
 * @version 2.0.0
 * @date 2020-07-10
 */
public enum MemberRegisterSourceEnum {
    /**
     * WEB企业商城申请 - 1
     */
    FROM_ENTERPRISE_WEB_SHOP(1, "WEB企业商城申请"),

    /**
     * H5企业商城申请 - 2
     */
    FROM_ENTERPRISE_H5_WEB_SHOP(2, "H5企业商城申请"),

    /**
     * WEB渠道商城申请 - 3
     */
    FROM_CHANNEL_WEB_SHOP(3, "WEB渠道商城申请"),

    /**
     * H5渠道商城申请 - 4
     */
    FROM_CHANNEL_H5_WEB_SHOP(4, "H5渠道商城申请"),

    /**
     * 平台代录入注册 - 5
     */
    FROM_PLATFORM_IMPORT(5, "平台代录入注册"),

    /**
     * 商户代录入注册 - 6
     */
    FROM_MERCHANT_IMPORT(6, "商户代录入注册"),

    /**
     * 渠道代录入注册 - 7
     */
    FROM_CHANNEL_IMPORT(7, "渠道代录入注册"),

    /**
     * APP企业商城申请 - 8
     */
    FROM_ENTERPRISE_APP_SHOP(8, "APP企业商城申请"),

    /**
     * APP渠道商城申请 - 9
     */
    FROM_CHANNEL_APP_SHOP(9, "APP渠道商城申请"),

    /**
     * APP渠道自有商城申请 - 10
     */
    FROM_CHANNEL_APP_PROPERTY_SHOP(10, "APP渠道自有商城申请"),

    /**
     * APP积分商城申请 - 11
     */
    FROM_ENTERPRISE_APP_SCORE_SHOP(11, "APP积分商城申请"),

    /**
     * APP渠道积分商城申请 - 12
     */
    FROM_CHANNEL_APP_SCORE_SHOP(12, "APP渠道积分商城申请"),

    /**
     * 小程序企业商城申请 - 13
     */
    FROM_ENTERPRISE_MINI_APP(13, "小程序企业商城申请"),

    /**
     * 小程序渠道商城申请 - 14
     */
    FROM_CHANNEL_MINI_APP(14, "小程序渠道商城申请"),

    /**
     * 小程序渠道自有商城申请 - 15
     */
    FROM_CHANNEL_PROPERTY_MINI_APP(15, "小程序渠道自有商城申请"),

    /**
     * 小程序积分商城申请 - 16
     */
    FROM_ENTERPRISE_SCORE_MINI_APP(16, "小程序积分商城申请"),

    /**
     * 小程序渠道积分商城申请 - 17
     */
    FROM_CHANNEL_SCORE_MINI_APP(17, "小程序渠道积分商城申请"),

    /**
     * 业务管理平台 - 99
     */
    FROM_MANAGE_PLATFORM(99, "平台后台"),

    /**
     * 未知来源 - 100
     */
    UNKNOWN(100, "未知");


    private final Integer code;

    MemberRegisterSourceEnum(Integer code, String msg) {
        this.code = code;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return LanguageHolder.getName(this.getClass(), this.getCode());
    }

    public static String getCodeMessage(Integer code) {
        return LanguageHolder.getName(MemberRegisterSourceEnum.class, code);
    }

    public static List<Integer> toList() {
        return Arrays.stream(MemberRegisterSourceEnum.values()).filter(c -> !c.getCode().equals(MemberRegisterSourceEnum.FROM_MANAGE_PLATFORM.getCode()) && !c.getCode().equals(MemberRegisterSourceEnum.UNKNOWN.getCode())).map(MemberRegisterSourceEnum::getCode).collect(Collectors.toList());
    }

    public static MemberRegisterSourceEnum parseInt(Integer code) {
        return Arrays.stream(MemberRegisterSourceEnum.values()).filter(c -> c.getCode().equals(code)).findFirst().orElse(MemberRegisterSourceEnum.FROM_ENTERPRISE_WEB_SHOP);
    }

    /**
     * 会员能力中查询注册来源下拉框列表
     * @return 下拉框列表
     */
    public static List<DropdownItem> toAbilityDropdownList() {
        return Arrays.stream(MemberRegisterSourceEnum.values()).filter(c -> !c.getCode().equals(MemberRegisterSourceEnum.FROM_MANAGE_PLATFORM.getCode()) && !c.getCode().equals(MemberRegisterSourceEnum.UNKNOWN.getCode())).sorted(Comparator.comparingInt(MemberRegisterSourceEnum::getCode)).map(e -> new DropdownItem(e.getCode(), e.getMsg())).collect(Collectors.toList());
    }

    /**
     * 平台后台 - 会员维护 - 下拉框列表
     * @return 下拉框列表
     */
    public static List<DropdownItem> toPlatformDropdownList() {
        return Arrays.stream(MemberRegisterSourceEnum.values()).filter(c -> !c.getCode().equals(MemberRegisterSourceEnum.UNKNOWN.getCode())).sorted(Comparator.comparingInt(MemberRegisterSourceEnum::getCode)).map(e -> new DropdownItem(e.getCode(), e.getMsg())).collect(Collectors.toList());
    }
}
